# Dockerfile - CentOS 7
# https://github.com/openresty/docker-openresty

FROM centos:7

#MAINTAINER Evan Wies <evan@neomantra.net>
MAINTAINER zouyi <zougangmu@qq.com>

# Docker Build Arguments
ARG RESTY_J="1"
ARG RESTY_VERSION="1.11.2.5"
ARG LOR_VERSION="0.3.4"
ARG RESTY_CONFIG_OPTION="\
    --prefix=/opt/openresty/nginx \
    --with-http_gunzip_module \
    --with-http_gzip_static_module \
    --with-http_realip_module \
    --with-http_slice_module \
    --with-http_ssl_module \
    --with-http_v2_module \
    --with-ipv6 \
    --with-md5-asm \
    --with-pcre-jit \
    --with-sha1-asm \
    --with-stream \
    --with-stream_ssl_module \
    --with-threads \
    "

# These are not intended to be user-specified


# 1) Install yum dependencies
# 2) Download and untar OpenSSL, PCRE, and OpenResty
# 3) Build OpenResty
# 4) Cleanup
RUN yum install -y \
        pcre-devel \
        openssl-devel \
        gcc-c++ \
        make \
        perl \
        perl-ExtUtils-Embed \
        readline-devel \
        unzip \
        zlib-devel \
    && yum clean all \
    && cd /tmp \
    && curl -fSL https://openresty.org/download/openresty-${RESTY_VERSION}.tar.gz -o openresty-${RESTY_VERSION}.tar.gz \
    && tar xzf openresty-${RESTY_VERSION}.tar.gz \
    && curl -fSL https://github.com/sumory/lor/archive/v${LOR_VERSION}.tar.gz -o v${LOR_VERSION}.tar.gz \
    && tar xzf v${LOR_VERSION}.tar.gz \
    && mv lor-${LOR_VERSION} /usr/local/lor \
    && cd /tmp/openresty-${RESTY_VERSION} \
    && ./configure -j${RESTY_J} ${RESTY_CONFIG_OPTION} \
    && make -j${RESTY_J} \
    && make -j${RESTY_J} install \
    && rm -rf /tmp/openresty* \
    && rm -rf /tmp/v*

# Add additional binaries into PATH for convenience
ENV PATH=$PATH:/opt/openresty/luajit/bin/:/opt/openresty/nginx/sbin/:/opt/openresty/bin/

ENTRYPOINT ["/opt/openresty/bin/openresty", "-c","/opt/openresty/nginx/conf/nginx.conf","-g", "daemon off;"]